From: Ewan Mellor Date: Wed, 27 Dec 2006 11:49:59 +0000 (+0000) Subject: Tidy and fix bindings for the SR class. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~15422^2~149 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=bbe21e102eb6a715b7eb36b2582cd38840d29860;p=xen.git Tidy and fix bindings for the SR class. Signed-off-by: Ewan Mellor --- diff --git a/tools/python/xen/xend/XendAPI.py b/tools/python/xen/xend/XendAPI.py index e52c2ead3c..e7215e56af 100644 --- a/tools/python/xen/xend/XendAPI.py +++ b/tools/python/xen/xend/XendAPI.py @@ -100,6 +100,7 @@ def catch_typeerror(func): try: return func(self, *args, **kwargs) except TypeError, exn: + #log.exception('catch_typeerror') if hasattr(func, 'api') and func.api in argcounts: # Assume that if the exception was thrown inside this # file, then it is due to an invalid call from the client, @@ -1446,37 +1447,40 @@ class XendAPI: return xen_api_success(sr.get_record()) # Attribute acceess - def SR_get_VDIs(self, session, sr_ref): - sr = XendNode.instance().get_sr() - return xen_api_success(sr.list_images()) - def SR_get_virtual_allocation(self, session, sr_ref): - sr = XendNode.instance().get_sr() - return sr.used_space_bytes() + def _get_SR_func(self, _, func, conv = None): + result = getattr(XendNode.instance().get_sr(), func)() + if conv: + result = conv(result) + return xen_api_success(result) + + def _get_SR_attr(self, _, attr): + return xen_api_success(str(getattr(XendNode.instance().get_sr(), + attr))) + + def SR_get_VDIs(self, _, ref): + return self._get_SR_func(ref, 'list_images') + + def SR_get_virtual_allocation(self, _, ref): + return self._get_SR_func(ref, 'virtual_allocation', str) - def SR_get_physical_utilisation(self, session, sr_ref): - sr = XendNode.instance().get_sr() - return sr.used_space_bytes() + def SR_get_physical_utilisation(self, _, ref): + return self._get_SR_func(ref, 'used_space_bytes', str) - def SR_get_physical_size(self, session, sr_ref): - sr = XendNode.instance().get_sr() - return sr.total_space_bytes() + def SR_get_physical_size(self, _, ref): + return self._get_SR_func(ref, 'total_space_bytes', str) - def SR_get_type(self, session, sr_ref): - sr = XendNode.instance().get_sr() - return xen_api_success(sr.type) + def SR_get_type(self, _, ref): + return self._get_SR_attr(ref, 'type') - def SR_get_location(self, session, sr_ref): - sr = XendNode.instance().get_sr() - return xen_api_success(sr.location) + def SR_get_location(self, _, ref): + return self._get_SR_attr(ref, 'location') - def SR_get_name_label(self, session, sr_ref): - sr = XendNode.instance().get_sr() - return xen_api_success(sr.name_label) + def SR_get_name_label(self, _, ref): + return self._get_SR_attr(ref, 'name_label') - def SR_get_name_description(self, session, sr_ref): - sr = XendNode.instance().get_sr() - return xen_api_success(sr.name_description) + def SR_get_name_description(self, _, ref): + return self._get_SR_attr(ref, 'name_description') def SR_set_name_label(self, session, sr_ref, value): sr = XendNode.instance().get_sr() diff --git a/tools/python/xen/xend/XendStorageRepository.py b/tools/python/xen/xend/XendStorageRepository.py index 42568e84a7..3ab5480a81 100644 --- a/tools/python/xen/xend/XendStorageRepository.py +++ b/tools/python/xen/xend/XendStorageRepository.py @@ -294,7 +294,11 @@ class XendStorageRepository: """ self.lock.acquire() try: - return self.storage_max + if self.storage_max == XEND_STORAGE_NO_MAXIMUM: + stfs = os.statvfs(self.location) + return stfs.f_blocks * stfs.f_frsize + else: + return self.storage_max finally: self.lock.release() @@ -304,10 +308,17 @@ class XendStorageRepository: """ self.lock.acquire() try: - total_used = 0 - for val in self.images.values(): - total_used += val.physical_utilisation - return total_used + return self.storage_used + finally: + self.lock.release() + + def virtual_allocation(self): + """Returns the total virtual space allocated within the storage repo. + @rtype: int + """ + self.lock.acquire() + try: + return self.storage_alloc finally: self.lock.release()